package hz.mobileproject.pda.ui.adapter;

import android.graphics.Color;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import java.util.List;

import hz.mobileproject.pda.R;
import hz.mobileproject.pda.entity.response.Response_grid_loadtype;

/**
 * Created by zmybi on 2017/1/24.
 */

public class GridWangDianMsgAdapter extends BaseAdapter {

    private List<Response_grid_loadtype> times;
    private int clickPosition;

    public GridWangDianMsgAdapter(List<Response_grid_loadtype> times) {
       this.times = times;
    }

    @Override
    public int getCount() {
        return times == null ? 0 :times.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if(convertView == null) {
            convertView = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_wwangdianqiandao_time,parent,false);
            viewHolder = new ViewHolder();
            viewHolder.tv_time = (TextView) convertView.findViewById(R.id.tv_time);
            convertView.setTag(viewHolder);

        }else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        viewHolder.tv_time.setGravity(Gravity.CENTER_HORIZONTAL);
        //数据和视图的绑定
        viewHolder.tv_time.setText(times.get(position).title);
        //更改文字颜色和背景颜色
        if(position == clickPosition) {
            viewHolder.tv_time.setTextColor(Color.parseColor("#0AA8DF"));
            convertView.setBackgroundColor(Color.parseColor("#f9f9fc"));

        }else {
            viewHolder.tv_time.setTextColor(Color.parseColor("#B4B4B4"));
            convertView.setBackgroundColor(Color.parseColor("#ffffff"));
        }

        return convertView;


    }

    public void setClickPosition(int position) {
        this.clickPosition = position;
        notifyDataSetChanged();
    }


    static class ViewHolder {
        TextView tv_time;
    }


}
